home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.sprintlink.net!news1!ts02-and-07
- From: dlmiller@iquest.net (Doug & Rose Miller)
- Subject: Re: NEwbie: How to return a multi-dimensional array from function?
- X-Nntp-Posting-Host: ts02-and-07.iquest.net
- Message-ID: <DoE3K0.H4y@iquest.net>
- Sender: news@iquest.net (News Admin)
- Organization: IQuest Network Services
- X-Newsreader: News Xpress Version 1.0 Beta #2.1
- References: <mjs.826298629@hubcap> <4ib78s$6gv@news.bridge.net> <4ic3p3$cl5@news.xs4all.nl> <4ic8pj$c99@news.bridge.net>
- Date: Sun, 17 Mar 1996 02:09:11 GMT
-
- psycho@bridge.net (Gary Thompson) wrote:
- +falstaff@xs4all.nl (Falstaff) wrote:
- +
- +>psycho@bridge.net (Gary Thompson) writes:
- +
- +>>>Two things: (1) If you are going to use the value of tmp outside of Foo(),
- +>>>then you need to declare
- +>>> static tmp[10][5];
- +>>>Otherwise the storage may disappear when you return from Foo().
- +
- +>>No, declaring it as static will only retain the value in the foo() function, if
- +>>you call it more than once. You CANNOT use a value declared in a subfunction in
- +>>MAIN. You would have to remove both TMP declarations from MAIN and FOO and
- +>>declare the thing globally outside of main.
- +
- +>WRONG!!!
- +
- +>If you declare a function
- +
- +>int *demo(void)
- +>{ static int n=0;
- +> n++;
- +> return &n;
- +>}
- +
- +>the caller can use the static variable until the next time your function
- +>is called. This is how the standard library function tmpnam() returns,
- +>for example.
- +
- +Well, of course it will work in your example... you returned the value.
-
- returning the value _is_ what the original post asked for, so what's your beef?
-